<?php


namespace api\channel\jutuike;


use Carbon\Carbon;

/**
 * 出行&加油
 * Class TravelUnion
 * @package api\channel\jutuike
 */
class TravelUnion extends Union
{
    //初始化
    public function __construct()
    {
        parent::__construct(PRODUCT_TRAVEL_OIL_SERV);
    }

    /**
     * 前端调用
     */
    const TRAVELSTATICDATA = [
        [
            'id' => 1,
            'act_id' => 42,
            'name' => '滴滴打车',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/04/23/LfKCVO.png'
        ],
        [
            'id' => 4,
            'act_id' => 49,
            'name' => '花小猪打车',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/04/23/LfKVxI.png'
        ],
        [
            'id' => 99,
            'act_id' => 47,
            'name' => '高德打车',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/04/23/LfKkPH.png'
        ],
        [
            'id' => 2,
            'act_id' => 43,
            'name' => '滴滴加油',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/04/23/LfKiIe.png'
        ],
        [
            'id' => 3,
            'act_id' => 44,
            'name' => '滴滴货运',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/04/23/LfKPaD.png'
        ],
        [
            'id' => 5,
            'act_id' => 67,
            'name' => '滴滴代驾',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/04/23/LfKpqK.png'
        ],
        [
            'id' => 87,
            'act_id' => 87,
            'name' => '同程打车',
            'type' => 'travel',
            'image_url' => 'https://s1.ax1x.com/2022/08/23/v6zydI.png'
        ],
    ];


    /**
     *  跳转链接
     *
     *
     * @param $type 1-打车、2-加油 -3货运 4-花小猪 5-代驾
     * @param $args 其他需要的参数, agent_id, user_id
     */
    public function productUrl($type, $args = [])
    {
        $mobile = $args['mobile'] ?? '';

        $sid = $this->getSid($args['agent_id'], $args['user_id'], $args['channel_id'] ?? '');

        $url = $this->baseUrl . '/didi/act';

        $defaults = [
            'sid' => $sid,
            'type' => $type,
            'link_type' => 'h5',
            'mobile' => $mobile,
        ];

        $data = [
            'apikey' => $this->apikey,
        ];

        $data = handleParameters($data, $defaults, $args);

        $res = curlPost($url, $data);
        $res = json_decode($res, true);

        return $res['data']['short_click_url'] ?? [];
    }


    /**
     *  跳转链接
     *
     *
     * @param $type 1-打车、2-加油 -3货运 4-花小猪 5-代驾
     * @param $args 其他需要的参数, agent_id, user_id
     */
    public function gaodeUrl(array $args = [])
    {
        $sid = $this->getSid($args['agent_id'], $args['user_id'], $args['channel_id'] ?? '');

        $url = $this->baseUrl . '/amap/act';

        $defaults = [
            'sid' => $sid,
            'type' => 1,
            'link_type' => 'h5'
        ];

        $data = [
            'apikey' => $this->apikey,
        ];

        $data = handleParameters($data, $defaults, $args);


        $res = curlPost($url, $data);
        $res = json_decode($res, true);


        return $res['data']['short_click_url'] ?? [];
    }


}